package spittr.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import spittr.service.SpittleService;

@Controller
@RequestMapping("/spittles")
public class SpittleController {
    @Autowired
    SpittleService service;

    @RequestMapping({"/all","/"})
    public String showAllSpittles(Model model){
        model.addAttribute("spittleList",service.getSpittleList());
        return "spittlesPage";
    }
    @RequestMapping("/{authorName}")
    public String showSpittle(@PathVariable("authorName") String authorName, Model model){
        model.addAttribute("spittleList",service.getSpittlesByAuthorName(authorName));
        return "spittlesPage";
    }
}
